<?
	session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php CheckAdmin2();?>

<html>
<head>
<title><?php echo $GuildName;?> - DKP系统</title>
<script language="JavaScript" src="inc/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Generator" content="EditPlus">
<meta name="Author" content="SULei">
<meta name="Keywords" content="DKP WOW GUILD">
<meta name="Description" content="">
<link href="<?php echo $StylePath;?>/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="<?php echo $StylePath;?>/styleplus.js"></script>
<style type="text/css" media="all">
</style>

</head>

<body>
<div class="header">
<?php require "menu.php"; ?>
</div>
<div class="main">
<div>
<b>注意:请在生成数据文件前确认,已经通过生成所有DKP列表完成了数据缓存更新.</b>
</div>
<table class="outframe">
	<tr>
		<th colspan="2">输出DKP数据到MerDKP插件</th>
	</tr>
	</tr>
	<tr><td></td><td><a href='?action=MerDKP2' class='abtn'>生成MerDKP 2.0 用数据文件</a></td></tr>
</table>


<table class="outframe">
	<tr>
		<th colspan="2">输出用于DKPtable插件的DKP数据</th>
	</tr>
	<tr class="coltitle"><td colspan="2">图形化的dkp数据查询插件,可同时支持多套dkp的查询 <a href="http://bbs.game.mop.com/viewthread.php?tid=1179228&extra=page%3D1" target="_blank">点击查看详细</a></td></tr>
	</tr>
	<tr><td>操作:</td><td><a href='?action=DKPtable'>生成文件 (Dkp_table1.15适用)</a></td></tr>
</table>

<table class="outframe interlace">
<tr>
	<th colspan="2">输出用于dkp_system插件的DKP数据</th>
</tr>
<tr class="coltitle"><td>分类</td><td>操作</td></tr>
<?php 
$sql="select * from raid_class";
$result = mysql_query($sql);$sql$conn
for ($i=1; $i<=$result->recordcount; $i=$i+1) {
	print "<tr><td>".$result["class_name"]."</td><td><a href='?action=dkpsystem&amp;id=".$result["id"]."'>生成文件</a></td></tr>";
	$result->movenext;

}

$result->close;
?>
<tr class="coltitle"><td colspan="2">注意:在输出之前请现在点击生成DKP详表以更新到最新数据</td></tr>
</table>

<?php 
if (${"action"}=="dkpsystem") {

} 


switch (${"action"}) {
	case "dkpsystem":
		print "<div class='message'><h3>下载文件</h3><div>";
export_dkpsystem();
		print "</div></div>";
		break;
	case "MerDKP":
		print "<div class='message'><h3>下载文件</h3><div>";
export_MerDKP();
		print "</div></div>";
		break;
	case "MerDKP136":
		print "<div class='message'><h3>下载文件</h3><div>";
export_MerDKP136();
		print "</div></div>";
		break;
	case "MerDKP2":
		print "<div class='message'><h3>下载文件</h3><div>";
export_MerDKP2();
		print "</div></div>";
		break;
	case "DKPtable":
		print "<div class='message'><h3>下载文件</h3><div>";
export_DKPtable();
		print "</div></div>";
		break;
	case "DKPBackup":
dkpBackup();
		break;
} 
?>
</div>
<?php require "footer.php"; ?>
</body>
</html>
</head>

<body>
<?php 
function export_dkpsystem() {
	extract($GLOBALS);

	if (${"id"}=="" || !is_numeric(${"id"})) {
		return $function_ret;

	} 
	$total_players=0;
	$total_items=0;
	$total_points=0;
	$dkpdata=$dkpdata."--========================"."\r\n";
	$dkpdata=$dkpdata."-- Created by FSDKP"."\r\n";
	$dkpdata=$dkpdata."-- File Created at ".strftime("%m/%d/%Y %H:%M:%S %p")."\r\n";
	$dkpdata=$dkpdata."-- Guild:".$GuildName."\r\n";
	$dkpdata=$dkpdata."-- DKP分类:".raidclassText(${"id"})."\r\n";
	$dkpdata=$dkpdata."--========================"."\r\n";


	$dkpdata=$dkpdata."DKP_ROLL_PLAYERS = {"."\r\n";
	$sql="select * from player order by id desc";
	$result = mysql_query($sql);$sql  $conn
	for ($i=1; $i<=$result->recordcount; $i=$i+1) {
		$thisdkp=totaldkp($result["id"],${"id"});
		$dkpdata=$dkpdata."    [\"".$result["player_name"]."\"] = {"."\r\n";
		$dkpdata=$dkpdata."          [\"RaidPoints\"] = ".$thisdkp.","."\r\n";
		$dkpdata=$dkpdata."          [\"Class\"] = \"".$result["player_class"]."\","."\r\n";
		$dkpdata=$dkpdata."    },"."\r\n";
		$total_players=$total_players+1;
		$total_points=$total_points+$thisdkp;
		$result->movenext;

	}

	$result->close;
	$dkpdata=$dkpdata."}"."\r\n";

	$dkpdata=$dkpdata."DKP_ROLL_UPDATE_INFO = {"."\r\n";
	$dkpdata=$dkpdata."     [\"date\"] = \"".strftime("%m/%d/%Y %H:%M:%S %p")."\","."\r\n";
	$dkpdata=$dkpdata."     [\"process_dkp_ver\"] = \"FSDKP 1.3.1\","."\r\n";
	$dkpdata=$dkpdata."     [\"total_players\"] = ".$total_players.","."\r\n";
	$dkpdata=$dkpdata."     [\"total_items\"] = ".$total_items.","."\r\n";
	$dkpdata=$dkpdata."     [\"total_points\"] = ".$total_points.","."\r\n";
	$dkpdata=$dkpdata."}"."\r\n";



WriteFile("export/","sqlvars.lua.txt",$dkpdata);

	return $function_ret;
} 

function WriteFile($strFilepath,$strFilename,$strFileText) {
	extract($GLOBALS);

	// $objStream is of type "ADODB.Stream"
	$With$objStream;
	$Open;
	$Charset="utf-8";
	$Position=$objStream->Size;
	$WriteText=$strFileText;
	$SaveToFile$DOCUMENT_ROOT.$strFilepath.$strFilename
	$Close;
	return $function_ret;
} 
print "已保存文件: <a href='".$strFilepath.$strFilename."'>".$strFilepath.$strFilename."</a> (右键点击\"另存为\"下载后请去掉.txt后缀)";
$objStream=null;




Sub dkpBackup()
	'定义变量
	Dim XMLText
	Dim GuildName , GuildCreateDate ,GuildNote
	Dim Players , ArrLoot , ArrDKP
	Dim DICreateTime , DICreateBy , DIVersion

	'读取数据
	Sql="Select * from guild"
	rs.open sql,conn,1,1
		if rs.eof or rs.bof then
			Response.write "缺少公会信息"
			Response.End
		else
			GuildName = rs("guild_name")
			GuildCreateDate = rs("guild_createtime")
			GuildNote = rs("guild_sname")
		end if
	rs.close

	Sql="Select * From player order by player_name"
	rs.open sql,conn,1,1
		if rs.eof or rs.bof then
			Response.write "未找到成员"
			Response.End
		else
			Redim Players(rs.recordCount-1,7)
			for i = 0 to rs.recordCount-1
				Players(i,0) = rs("player_name")
				Players(i,1) = rs("player_class")
				Players(i,2) = rs("player_race")
				Players(i,3) = rs("player_level")
				Players(i,4) = "" 'ExtraInfo
				Players(i,5) = "" 'Looted
				Sql="Select * from player_dkp where player_id="&rs("id")&" order by raid_class"&c
				rs2.open sql,conn,1,1
					if rs2.eof or rs2.bof then
						Players(i,6) = "" 'DKP
					else
						for j = 1 to rs2.recordcount
						Players(i,6) = Players(i,6)&","&rs2("raid_class")&","&rs2("player_dkp") 'Looted
						rs2.movenext
						next
					end if
				rs2.close
				Players(i,7) = ""
				rs.movenext
			next
		end if
	rs.close

	'按格式输出
	XMLText = XMLText& "<?xml version=""1.0"" encoding=""gb2312""?>" &vbCrlf
	XMLText = XMLText& "<Guild>" &vbCrlf
	XMLText = XMLText& "	<GuildInfo>" &vbCrlf
	XMLText = XMLText& "		<GuildName>"&GuildName&"</GuildName>" &vbCrlf
	XMLText = XMLText& "		<GuildCreateDate>"&GuildCreateDate&"</GuildCreateDate>" &vbCrlf
	XMLText = XMLText& "		<GuildNote><![CDATA["&GuildNote&"]]></GuildNote>" &vbCrlf
	XMLText = XMLText& "	</GuildInfo>" &vbCrlf
	XMLText = XMLText& "	<Players>" &vbCrlf
	for i = 0 to Ubound(Players,1)
		XMLText = XMLText& "	<Player>" &vbCrlf
		XMLText = XMLText& "		<Name>"&Players(i,0)&"</Name>" &vbCrlf
		XMLText = XMLText& "		<PlayerClass>"&Players(i,1)&"</PlayerClass>" &vbCrlf
		XMLText = XMLText& "		<Race>"&Players(i,2)&"</Race>" &vbCrlf
		XMLText = XMLText& "		<Level>"&Players(i,3)&"</Level>" &vbCrlf
		XMLText = XMLText& "		<ExtraInfo><![CDATA["&Players(i,4)&"]]></ExtraInfo>" &vbCrlf

		XMLText = XMLText& "		<Looted>" &vbCrlf
		if Instr(Players(i,5),",")>0 then
		ArrDKP=Split(Right(Players(i,5),Len(Players(i,5))-1),",")
		for j = 0 to Ubound(ArrDKP) step 2
			XMLText = XMLText& "			<Item>" &vbCrlf
			XMLText = XMLText& "				<ItemName>""</ItemName>" &vbCrlf
			XMLText = XMLText& "				<ItemNote><![CDATA[xxx]]></ItemNote>" &vbCrlf
			XMLText = XMLText& "			</Item>" &vbCrlf
		next
		end if
		XMLText = XMLText& "		</Looted>" &vbCrlf

		XMLText = XMLText& "		<DKP>" &vbCrlf
		if Instr(Players(i,6),",")>0 then
		ArrDKP=Split(Right(Players(i,6),Len(Players(i,6))-1),",")
		for k = 0 to Ubound(ArrDKP) step 2
			XMLText = XMLText& "			<DKPClass>" &vbCrlf
			XMLText = XMLText& "				<ClassName>"&ArrDKP(k)&"</ClassName>" &vbCrlf
			XMLText = XMLText& "				<DKPCount>"&ArrDKP(k+1)&"</DKPCount>" &vbCrlf
			XMLText = XMLText& "			</DKPClass>" &vbCrlf
		next
		end if
		XMLText = XMLText& "		</DKP>" &vbCrlf

		XMLText = XMLText& "	</Player>" &vbCrlf
	next
	XMLText = XMLText& "	</Players>" &vbCrlf
	XMLText = XMLText& "	<DataInfo>" &vbCrlf
	XMLText = XMLText& "		<CreateTime>"&Now()&"</CreateTime>" &vbCrlf
	XMLText = XMLText& "		<CreateBy>FSDKP 1.3.0</CreateBy>" &vbCrlf
	XMLText = XMLText& "		<Version>1.0</Version>" &vbCrlf
	XMLText = XMLText& "	</DataInfo>" &vbCrlf
	XMLText = XMLText& "</Guild>"

	Response.write "<textarea name='' rows='15' cols='150'>"&XMLText&"</textarea>"
End Sub



function totaldkp(pid,c)
	sql="select * from player_dkp where player_id="&pid&" and raid_class="&c
	rs2.open sql,conn,1,1
		if rs2.eof or rs2.bof then
		SHowerror("数据未暂存,可能有新加入的成员没有获得在所有DKP类中的分数,请尝试生成全部DKP分类后再导出.")
		Response.end
		else
		totaldkp=rs2("player_dkp")
		end if
	rs2.close
end function




Sub  export_DKPtable()
	Dim ArrClass , membercount
	dim dkpdata,total_players,total_items,total_points

	Sql="Select * from raid_class"
	rs.open sql,conn,1,1
		if rs.eof or rs.bof then 
			Response.write "没有建立分类"
			exit sub
		end if
		Redim ArrClass(rs.recordcount-1,1)
		for i = 1 to rs.recordcount
			ArrClass(i-1,0)=rs("id")
			ArrClass(i-1,1)=rs("class_name")
			rs.movenext
		next
	rs.close
	
	dkpdata=dkpdata&"DKP_tables = {}" &vbCrlf
	for j = 0 to UBound(ArrClass) {" &vbCrlf

		sql="select * from player order by player_name"
		rs.open sql,conn,1,1
			membercount=rs.recordcount
			for i = 1 to rs.recordcount
				thisdkp=totaldkp(rs("id"),Arrclass(j,0)) { nick="""&rs("player_name")&""", class=DKPT_"&ProCN2EN(rs("player_class"))&", current="&thisdkp&", spent=0.00 }," &vbCrlf
			rs.movenext
			next
		rs.close
		dkpdata=dkpdata&"};" &vbCrlf
		dkpdata=dkpdata&"DKP_tables["&j+1&"].title = """&Arrclass(j,1)&""";" &vbCrlf
		dkpdata=dkpdata&"DKP_tables["&j+1&"].url = ""见公会信息"";" &vbCrlf
		dkpdata=dkpdata&"DKP_tables["&j+1&"].members = "&membercount&";" &vbCrlf
	next
	dkpdata=dkpdata&"DKP_tables_count = "&UBound(ArrClass)+1 &vbCrlf

	call WriteFile("export/","dkp.lua.txt",dkpdata) 
end sub




'MerDKP 2.0+ DataFormat
Sub  export_MerDKP2()
	Dim ArrClass , membercount , ClassText
	dim dkpdata,total_players,total_items,total_points

	Sql="Select * from raid_class"
	rs.open sql,conn,1,1
		if rs.eof or rs.bof then 
			Response.write "没有建立分类"
			exit sub
		end if
		Redim ArrClass(rs.recordcount-1,1)
		for i = 1 to rs.recordcount
			ArrClass(i-1,0)=rs("id")
			ArrClass(i-1,1)=rs("class_name")
			ClassText=ClassText&""""&rs("class_name")&""""&","
			rs.movenext
		next
	rs.close
	dkpdata=dkpdata&"Mer_DKP_UPDATETIME = """&getRT150Time(today)&""";" &vbCrlf
	dkpdata=dkpdata&"MerDKP_Table = {};" &vbCrlf

	dkpdata=dkpdata&"" &vbCrlf

	for j = 0 to UBound(ArrClass) {" &vbCrlf

		sql="select * from player  where player_lastraid > #"&DateADD("d",freezeday,today)&"#  order by player_name"
		rs.open sql,conn,1,1
			membercount=rs.recordcount
			for i = 1 to rs.recordcount
				thisdkp=totaldkp(rs("id"),Arrclass(j,0)) {name="""&rs("player_name")&""",class="""&getHeXieProfessionName(rs("player_class"))&""",dkp="&Round(thisdkp,2)&",online=1},"&vbCrlf
			rs.movenext
			next
		rs.close
		dkpdata=dkpdata&"};" &vbCrlf
		dkpdata=dkpdata&"MerDKP_Table["&j+1&"].title="""&ArrClass(j,1)&""";" &vbCrlf
		dkpdata=dkpdata&"MerDKP_Table["&j+1&"].whisper=""1"";" &vbCrlf
		dkpdata=dkpdata&"MerDKP_Table["&j+1&"].key="""&ArrClass(j,1)&""";" &vbCrlf
	next
	call WriteFile("export/","dkp_list.lua.txt",dkpdata) 
end sub


Function ProCN2EN(t)
	Select Case T
		Case "战士"
			ProCN2EN="warrior"
		Case "法师"
			ProCN2EN="mage"
		Case "牧师"
			ProCN2EN="priest"
		Case "圣骑士"
			ProCN2EN="paladin"
		Case "猎人"
			ProCN2EN="hunter"
		Case "德鲁伊"
			ProCN2EN="druid"
		Case "盗贼"
			ProCN2EN="rogue"
		Case "术士"
			ProCN2EN="warlock"
		Case "萨满祭司"
			ProCN2EN="shaman"
		Case else
			ProCN2EN="unknow"
		End Select
End Function
%>
